/**
 *
 *
 *
 */
import request from "@/utils/request";
import type {
  getUserManageObj,
  SaveUserParams,
  GetUserRoleListResponse,
} from "./model/userModel";

enum Api {
  GetUserManageListUrl = "/admin/acl/user",
  saveUserUrl = "/admin/acl/user/save",
  getUserRoleListUrl = "/admin/acl/user/toAssign",
  assignUserRoleUrl = "/admin/acl/user/doAssign",
}

/**
 *
 * @param page   请求第几页的页数
 * @param limit  一页显示几条数据
 * @param username  请求哪个用户
 * @returns
 */
export const getUserManageListApi = (
  page: number,
  limit: number,
  username: string
) => {
  return request.get<any, getUserManageObj>(
    Api.GetUserManageListUrl + `/${page}/${limit}`,
    {
      params: {
        username,
      },
    }
  );
};

/**
 * 添加用户
 * @param data SaveUserParams
 * @returns null
 */
export const saveUserApi = (data: SaveUserParams) => {
  return request.post<any, null>(Api.saveUserUrl, data);
};

// 获取角色列表
export const getUserRoleListApi = (userId: string) => {
  return request.get<any, GetUserRoleListResponse>(
    Api.getUserRoleListUrl + `/userId`
  );
};

/**
 * 给用户分配角色
 * @param userId 用户id
 * @param roleId 角色id列表
 * @returns null
 */
export const assignUserRoleApi = (userId: string, roleId: string[]) => {
  return request.post<any, null>(
    Api.assignUserRoleUrl,
    {},
    {
      params: {
        userId,
        roleId: roleId + "",
      },
    }
  );
};
